//
//  EmptyViewKitTool.m
//  AFNetworking
//
//  Created by 海参 on 2022/6/29.
//

#import "EmptyViewKitTool.h"

@implementation EmptyViewKitTool


+ (NSBundle *)bundle
{
    static NSBundle *bundle = nil;
    if (bundle == nil) {
        //.framework
        NSBundle *bundle1 = [NSBundle bundleForClass:[self class]];
        //.bundle
        NSString *path = [bundle1 pathForResource:@"CAIEmptyViewKit" ofType:@"bundle"];
        bundle = [NSBundle bundleWithPath:path];
    }
    return bundle;
}


+ (UIImage *)imageNamed:(NSString *)name
{
    NSBundle *bundle = [self bundle];
    UIImage *img = [UIImage imageNamed:name inBundle:bundle compatibleWithTraitCollection:nil];
    return img;
}


+ (CGFloat)safeAreaStatusBarHeight
{
    CGFloat statusBarHeight = 0;
    if (@available(iOS 13.0, *)) {
        //待确认
//        NSSet <UIScene *>*connectedScenes = [UIApplication sharedApplication].connectedScenes;
//        UIWindowScene *scene = nil;
//        if (![UIApplication sharedApplication].supportsMultipleScenes) {
//            scene = (UIWindowScene *)[[connectedScenes allObjects] firstObject];
//        }else{
//            for (UIWindowScene * windowScene in connectedScenes) {
//                if (windowScene.activationState == UISceneActivationStateForegroundActive) {
//                    scene = windowScene;
//                }
//            }
//        }
        NSSet *set = [UIApplication sharedApplication].connectedScenes;
        UIWindowScene *scene = (UIWindowScene *)[[set allObjects] firstObject];
        statusBarHeight = scene.statusBarManager.statusBarFrame.size.height;
    } else
    {
        statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
    }
    return statusBarHeight;
}

+ (CGFloat)safeAreaLayoutNormalBottom
{
    CGFloat safeAreaBottomHeight = 0;
    if (@available(iOS 13.0, *)) {
        
        NSSet <UIScene *>*connectedScenes = [UIApplication sharedApplication].connectedScenes;
        UIWindowScene *scene = nil;
        if (![UIApplication sharedApplication].supportsMultipleScenes) {
            scene = (UIWindowScene *)[[connectedScenes allObjects] firstObject];
        }else{
            for (UIWindowScene * windowScene in connectedScenes) {
                if (windowScene.activationState == UISceneActivationStateForegroundActive) {
                    scene = windowScene;
                }
            }
        }
        id sceneDelegate = scene.delegate;
        if (!sceneDelegate){
            UIEdgeInsets areaInset = [UIApplication sharedApplication].delegate.window.safeAreaInsets;
            safeAreaBottomHeight = areaInset.bottom;
        }
        else
        {
            if ([sceneDelegate respondsToSelector:@selector(setWindow:)])
            {
                safeAreaBottomHeight = [sceneDelegate window].safeAreaInsets.bottom;
            }
        }
    }
    else
    {
        if (@available(iOS 11.0, *)) {
            UIEdgeInsets areaInset = [UIApplication sharedApplication].delegate.window.safeAreaInsets;
            if (areaInset.bottom >0) {
                safeAreaBottomHeight = areaInset.bottom;
            }
        }
    }
    return safeAreaBottomHeight;
}

@end
